import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/model/health/sys_health_property.dart';
import 'package:flutter_eve_plugin/store/main.dart';
import 'package:flutter_eve_plugin/store_vm/app_vm.dart';
import 'package:flutter_eve_plugin/utils/image_util.dart';
import 'package:flutter_eve_plugin/utils/screen_util.dart';
import 'package:flutter_redux/flutter_redux.dart';

class SysChildHeaderWidget extends StatelessWidget {
  final int type;
  final PropertyHealthDataInfo info;

  const SysChildHeaderWidget({Key key, this.type, this.info}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return StoreConnector<AppState, AppStateViewModel>(
        converter: (store) => AppStateViewModel(state: store.state),
        builder: (context, vm) {
          String imgName = '';
          switch (type) {
            case 0:
              {
                if (info.healthGrade == 0) {
                  imgName = imageUtilHuPo('health/icon_breathe_health@2x');
                } else if (info.healthGrade == 1) {
                  imgName = imageUtilHuPo('health/icon_breathe_easy_sick@2x');
                } else {
                  imgName = imageUtilHuPo('health/icon_breathe_sick@2x');
                }
              }
              break;
            case 1:
              {
                if (info.healthGrade == 0) {
                  imgName = imageUtilHuPo('health/icon_digestion_health@2x');
                } else if (info.healthGrade == 1) {
                  imgName = imageUtilHuPo('health/icon_digestion_easy_sick@2x');
                } else {
                  imgName = imageUtilHuPo('health/icon_digestion_sick@2x');
                }
              }
              break;
            case 2:
              {
                if (info.healthGrade == 0) {
                  imgName = imageUtilHuPo('health/icon_movement_health@2x');
                } else if (info.healthGrade == 1) {
                  imgName = imageUtilHuPo('health/icon_movement_easy_sick@2x');
                } else {
                  imgName = imageUtilHuPo('health/icon_movement_sick@2x');
                }
              }
              break;
            case 3:
              {
                if (info.healthGrade == 0) {
                  imgName = imageUtilHuPo('health/icon_nerve_health@2x');
                } else if (info.healthGrade == 1) {
                  imgName = imageUtilHuPo('health/icon_nerve_easy_sick@2x');
                } else {
                  imgName = imageUtilHuPo('health/icon_nerve_sick@2x');
                }
              }
              break;
            case 4:
              {
                if (info.healthGrade == 0) {
                  imgName = imageUtilHuPo('health/icon_endocrine_health@2x');
                } else if (info.healthGrade == 1) {
                  imgName = imageUtilHuPo('health/icon_endocrine_easy_sick@2x');
                } else {
                  imgName = imageUtilHuPo('health/icon_endocrine_sick@2x');
                }
              }
              break;
          }

          return Container(
            decoration: BoxDecoration(
              image: DecorationImage(
                  image: AssetImage(imgName), fit: BoxFit.cover),
            ),
            margin: EdgeInsets.only(
                left: setRatio(3), top: setRatio(5), right: setRatio(3)),
            width: setRatio(370),
            height: setRatio(200),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Container(
                  constraints: BoxConstraints(
                      minHeight: setRatio(28),
                      minWidth: setRatio(110),
                      maxHeight: setRatio(28),
                      maxWidth: setRatio(160)),
                  decoration: BoxDecoration(
                      color: childColor(),
                      borderRadius: BorderRadius.circular(setRatio(28)),
                      boxShadow: [
                        BoxShadow(color: childColor(), blurRadius: setRatio(1))
                      ]),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: children(),
                  ),
                ),
                buildContainer()
              ],
            ),
          );
        });
  }

  Container buildContainer() {
    if (info.healthGrade == 1) {
      return Container(
        padding: EdgeInsets.only(
            left: setRatio(41), right: setRatio(41), top: setRatio(25)),
        child: Text(
          '当前系统健康值较低，随时可能生病哦~',
          style: TextStyle(color: Color(0xFFFFFFFF), fontSize: setTextSp(12)),
          textAlign: TextAlign.center,
        ),
      );
    }
    if (info.illnessDesc == null || info.illnessDesc.isEmpty) {
      return Container();
    }
    return Container(
      padding: EdgeInsets.only(
          left: setRatio(41), right: setRatio(41), top: setRatio(25)),
      child: Text(
        info.illnessDesc,
        style: TextStyle(color: Color(0xFFFFFFFF), fontSize: setTextSp(12)),
        textAlign: TextAlign.center,
      ),
    );
  }

  List<Widget> children() {
    if (info.healthGrade == 0) {
      return <Widget>[
        Text(
          '非常健康',
          style: TextStyle(color: Color(0xFF7A76FF), fontSize: setTextSp(16)),
        )
      ];
    } else if (info.healthGrade == 1) {
      return <Widget>[
        Text(
          '容易生病体质',
          style: TextStyle(color: Color(0xFFFB9C14), fontSize: setTextSp(16)),
        )
      ];
    } else if (info.healthGrade == 2) {
      return <Widget>[
        Text(
          info.illnessName,
          style: TextStyle(color: Color(0xFFF74040), fontSize: setTextSp(16)),
        )
      ];
    } else {
      return <Widget>[
        Text(
          info.illnessName,
          style: TextStyle(color: Color(0xFFF74040), fontSize: setTextSp(16)),
        ),
        SizedBox(
          width: setRatio(7),
        ),
        Image.asset(
          imageUtilHuPo('health/icon_warning_red@2x'),
          width: setRatio(16),
          height: setRatio(16),
        )
      ];
    }
  }

  Color childColor() {
    switch (info.healthGrade) {
      case 0:
      case 1:
        return Colors.white;
      case 2:
      case 3:
        return Color(0xFFFFE4E4);
      default:
        return Colors.white;
    }
  }
}
